package com.lovo.project2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.project2.bean.SaleBean;
import com.lovo.project2.mapper.ISaleBeanMapper;
import com.lovo.project2.service.ISaleBeanService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class SaleBeanServiceImpl extends ServiceImpl<ISaleBeanMapper, SaleBean> implements ISaleBeanService {
    @Override
    public IPage<SaleBean> querySaleBeanListByNameTime(IPage iPage, String clientName, LocalDate stateTime, LocalDate endTime) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if (clientName!=null&&!"".equals(clientName)){
            queryWrapper.like("client_name",clientName);
        }if (stateTime!=null&&!"".equals(stateTime)){
            queryWrapper.ge("sale_time",stateTime);
        }if (endTime!=null&&!"".equals(endTime)){
            queryWrapper.le("sale_time",endTime);
        }
        return baseMapper.selectPage(iPage,queryWrapper);
    }

    @Override
    public void addSaleBean(SaleBean saleBean) {
baseMapper.insert(saleBean);
    }

    @Override
    public SaleBean querySaleBeanById(int id) {

        return baseMapper.selectById(id);
    }
}
